
const register = require('@babel/register');
register({
  ignore: [/node_modules/],
  presets: ["@babel/preset-env", "@babel/preset-react"],
  plugins: ["@babel/plugin-transform-modules-commonjs"]
});
const webpack = require('webpack');
const express = require('express');
const static = require('serve-static');
const webpackConfig = require('./webpack.config');
const render = require('./render');
webpack(webpackConfig, (err, stats) => {
  const statsJSON = stats.toJson({ assets: true });
  const assets = statsJSON.assets.reduce((memo, { name }) => {
    memo[name] = `/` + name;
    return memo;
  }, {});
  const app = express();
  app.get('/', (req, res) => {
    render(req, res, assets);
  });
  //设置静态文件根目录 /main.js 会返回build目录下面的main.js
  app.use(static('build'));
  app.listen(8080, () => console.log(`server started at port 8080`));
});